/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufba.lasid.v1.jitclouds.mda.providers;

import br.ufba.lasid.v1.jitclouds.mda.MDA;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.BasicConfiguration;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.ft.RemusBasedVMFailoverDeployer;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.ft.IVMFailoverDeployer;
import java.util.List;
import java.util.Properties;

/**
 *
 * @author aliriosa
 */
public class RemusBasedVMFailoverDeployerProvider implements IProvider<IVMFailoverDeployer> {

    @Override
    public IVMFailoverDeployer create(Properties options) throws Exception {
        
        RemusBasedVMFailoverDeployer remus = new RemusBasedVMFailoverDeployer();
        
        String idFDeployer = MDA.BaseOptions.getProperty(MDA.VMFailoverDeployerTag);
        String dsFDeployer = MDA.Configuration.getString(idFDeployer + ".description");
        String period = MDA.Configuration.getString(idFDeployer + ".period", "500");
        
        remus.setID(idFDeployer);
        remus.setDescription(dsFDeployer);
        remus.setPeriod(Long.parseLong(period));
        
        List actions = MDA.Configuration.getList("remus.action");
        
        BasicConfiguration config = new BasicConfiguration();
        
        if(actions != null && !actions.isEmpty()){
            for(Object action : actions){
                String command = MDA.Configuration.getString("remus." + action);
                config.set(action.toString(), command);
            }            
        }
        
        remus.setConfiguration(config);
        
        MDA.debug("The VM Failover Deployer " + remus.getID() + "[" + remus.getDescription() + "] has been successfully loaded.");                    
        
        return remus;
    }
    
}
